package top.lyunk.demo.akka;

import akka.actor.AbstractActor;
import akka.actor.ReceiveTimeout;

import java.time.Duration;

public class ReceiveTimeoutActor extends AbstractActor {
    public ReceiveTimeoutActor() {
        // 当该Actor非活动超时后，会出发超时异常
        getContext().setReceiveTimeout(Duration.ofSeconds(10));
    }

    @Override
    public Receive createReceive() {
        return receiveBuilder()
                // 非活动异常
                .match(ReceiveTimeout.class,
                        r -> getContext().cancelReceiveTimeout())
                .build();
    }
}
